﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Globalization;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Effects;
using System.ComponentModel;

namespace proj4
{
    /// <summary>
    /// Interaction logic for ResultWindow.xaml
    /// </summary>
    public partial class ResultWindow : Window
    {
        private int time;
        private int matched;
        private string _usrName = "Jan Kowalski";
        public String usrName { get { return _usrName; } set { _usrName = value; } }
        public ResultWindow()
        {
            InitializeComponent();
        }

        private TimeSpan ConvertToTimeSpan()
        {
            var hours = time / 3600;
            var minutes = (time % 3600) / 60;
            var seconds = time % 60;
            return new TimeSpan(hours, minutes, seconds);
        }

        public bool? ShowDialog(int _time, int _matched, bool win)
        {
            time = _time;
            matched = _matched;
            TimeSpan newTime = this.ConvertToTimeSpan();
            message.Content = win ? String.Format("You won! You connected all {0} puzzles. Your time:", matched) :
                                    String.Format("You connected only {0} puzzle(s). Your time:", matched);
            currTime.Content = String.Format(CultureInfo.CurrentCulture, "Time: {0:00}:{1:00}:{2:00}", newTime.Hours, newTime.Minutes, newTime.Seconds);

            return this.ShowDialog();
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var text = sender as TextBox;
            usrName = text.Text;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }
    }
}
